home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 176-200 / disk_195 / microemacs / src.zoo / char.c < prev    next >
C/C++ Source or Header  |  1989-03-23  |  6KB  |  275 lines

  1. /*    CHAR.C:    Character handling functions for
  2.         MicroEMACS 3.10
  3.         (C)opyright 1988 by Daniel Lawrence
  4.  
  5.         ALL THE CODE HERE IS FOR VARIOUS FORMS OF ASCII AND
  6.         WILL HAVE TO BE MODIFIED FOR EBCDIC
  7. */
  8.  
  9. #include    <stdio.h>
  10. #include    "estruct.h"
  11. #include    "etype.h"
  12. #include    "edef.h"
  13. #include    "elang.h"
  14.  
  15. #if    DIACRIT
  16. /*    isletter()
  17.         Is the character a letter?  We presume a letter must
  18.     be either in the upper or lower case tables (even if it gets
  19.     translated to itself).
  20. */
  21.  
  22. int PASCAL NEAR isletter(ch)
  23.  
  24. register unsigned int ch;
  25.  
  26. {
  27.     return(isupper(ch) || islower(ch));
  28. }
  29.  
  30. /*    islower()
  31.         Is the character a lower case letter?  This looks
  32.     in the lower to uppercase translation table.
  33. */
  34.  
  35. int PASCAL NEAR islower(ch)
  36. register unsigned int    ch;
  37. {
  38.     return(lowcase[ch] != 0);
  39. }
  40.  
  41. /*    isupper()
  42.         Is the character a upper case letter?  This looks
  43.     in the upper to lowercase translation table.
  44. */
  45.  
  46. int PASCAL NEAR isupper(ch)
  47. register unsigned int    ch;
  48. {
  49.     return(upcase[ch] != 0);
  50. }
  51.  
  52. /*    chcase()
  53.  
  54.         Change the case of the current character.
  55.     First check lower and then upper.  If it is not a letter,
  56.     it gets returned unchanged.
  57. */
  58.  
  59. unsigned int PASCAL NEAR chcase(ch)
  60. register unsigned int    ch;
  61. {
  62.     /* translate lowercase */
  63.     if (islower(ch))
  64.         return(lowcase[ch]);
  65.  
  66.     /* translate uppercase */
  67.     if (isupper(ch))
  68.         return(upcase[ch]);
  69.  
  70.     /* let the rest pass */
  71.     return(ch);
  72. }
  73.  
  74. /* change *cp to an upper case character */
  75.  
  76. uppercase(cp)
  77.  
  78. char *cp;    /* ptr to character to uppercase */
  79.  
  80. {
  81.     /* translate lowercase */
  82.     if (islower(*cp))
  83.         *cp = lowcase[*cp];
  84. }
  85.  
  86. /* change *cp to an lower case character */
  87.  
  88. lowercase(cp)
  89.  
  90. char *cp;    /* ptr to character to lowercase */
  91.  
  92. {
  93.     /* translate lowercase */
  94.     if (isupper(*cp))
  95.         *cp = upcase[*cp];
  96. }
  97.  
  98. char PASCAL NEAR upperc(ch)    /* return the upper case equivalant of a character */
  99.  
  100. char ch;    /* character to get uppercase euivalant of */
  101.  
  102. {
  103.     if (islower(ch))
  104.         return(lowcase[ch]);
  105.     else
  106.         return(ch);
  107. }
  108.  
  109. char PASCAL NEAR lowerc(ch)    /* return the lower case equivalant of a character */
  110.  
  111. char ch;    /* character to get lowercase equivalant of */
  112.  
  113. {
  114.     if (isupper(ch))
  115.         return(upcase[ch]);
  116.     else
  117.         return(ch);
  118. }
  119.  
  120. PASCAL NEAR initchars()    /* initialize the character upper/lower case tables */
  121.  
  122. {
  123.     register int index;    /* index into tables */
  124.  
  125.     /* all of both tables to zero */
  126.     for (index = 0; index < HICHAR; index++) {
  127.         lowcase[index] = 0;
  128.         upcase[index] = 0;
  129.     }
  130.  
  131.     /* lower to upper */
  132.     for (index = 'a'; index <= 'z'; index++)
  133.         lowcase[index] = index - DIFCASE;
  134.  
  135.     /* upper to lower */
  136.     for (index = 'A'; index <= 'Z'; index++)
  137.         upcase[index] = index + DIFCASE;
  138.  
  139. #if    MSDOS
  140.     /* setup various extended IBM-PC characters */
  141.     upcase[0x80]  = 0x87;    /* C with a cedilla */
  142.     lowcase[0x81] = 0x9a;    /* U with an umlat */
  143.     lowcase[0x82] = 0x90;    /* E with an acute accent */
  144.     lowcase[0x83] = 0x83;    /* A with two dots */
  145.     lowcase[0x84] = 0x8e;    /* A with an umlat */
  146.     lowcase[0x85] = 0x85;    /* A with a grave accent */
  147.     lowcase[0x86] = 0x8f;    /* A with a circle */
  148.     lowcase[0x87] = 0x80;    /* C with a cedilla */
  149.     lowcase[0x88] = 0x88;    /* E with a ^ */
  150.     lowcase[0x89] = 0x89;    /* E with two dots */
  151.     lowcase[0x8a] = 0x8a;    /* E with a grave accent */
  152.     lowcase[0x8b] = 0x8b;    /* I with two dots */
  153.     lowcase[0x8c] = 0x8c;    /* I with a ^ */
  154.     lowcase[0x8d] = 0x8d;    /* I with a grave accent */
  155.     upcase[0x8e]  = 0x84;    /* A with an umlat */
  156.     upcase[0x8f]  = 0x86;    /* A with a circle */
  157.     upcase[0x90]  = 0x82;    /* E with an acute accent */
  158.     lowcase[0x91] = 0x92;    /* AE combination */
  159.     upcase[0x92]  = 0x91;    /* AE combination */
  160.     lowcase[0x93] = 0x93;    /* O with a ^ */
  161.     lowcase[0x94] = 0x99;    /* O with an umlat */
  162.     lowcase[0x95] = 0x95;    /* O with an acute accent */
  163.     lowcase[0x96] = 0x96;    /* U with a ^ */
  164.     lowcase[0x97] = 0x97;    /* U with an grave accent */
  165.     lowcase[0x98] = 0x98;    /* Y with two dots */
  166.     upcase[0x99]  = 0x94;    /* O with an umlat */
  167.     upcase[0x9a]  = 0x81;    /* U with an umlat */
  168.     lowcase[0xa0] = 0xa0;    /* A with an acute accent */
  169.     lowcase[0xa1] = 0xa1;    /* I with an acute accent */
  170.     lowcase[0xa2] = 0xa2;    /* O with an acute accent */
  171.     lowcase[0xa3] = 0xa3;    /* U with an acute accent */
  172.     lowcase[0xa4] = 0xa5;    /* N with a ...... */
  173.     upcase[0xa5]  = 0xa4;    /* N with a ...... */
  174.     lowcase[0xa6] = 0xa6;    /* A underlined */
  175.     lowcase[0xa7] = 0xa7;    /* O underlined */
  176. #endif
  177. }
  178.  
  179. /*    Set a character in the lowercase map */
  180.  
  181. int PASCAL NEAR setlower(ch, val)
  182.  
  183. char *ch;    /* ptr to character to set */
  184. char *val;    /* value to set it to */
  185.  
  186. {
  187.     return(lowcase[*ch & 255] = *val & 255);
  188. }
  189.  
  190. /*    Set a character in the uppercase map */
  191.  
  192. int PASCAL NEAR setupper(ch, val)
  193.  
  194. char *ch;    /* ptr to character to set */
  195. char *val;    /* value to set it to */
  196.  
  197. {
  198.     return(upcase[*ch & 255] = *val & 255);
  199. }
  200. #else
  201. /* change *cp to an upper case character */
  202.  
  203. uppercase(cp)
  204.  
  205. char *cp;    /* ptr to character to uppercase */
  206.  
  207. {
  208.     /* translate lowercase */
  209.     if (islower(*cp))
  210.         *cp -= DIFCASE;
  211. }
  212.  
  213. /* change *cp to an lower case character */
  214.  
  215. lowercase(cp)
  216.  
  217. char *cp;    /* ptr to character to lowercase */
  218.  
  219. {
  220.     /* translate lowercase */
  221.     if (isupper(*cp))
  222.         *cp += DIFCASE;
  223. }
  224.  
  225. char PASCAL NEAR upperc(ch)    /* return the upper case equivalant of a character */
  226.  
  227. char ch;    /* character to get uppercase euivalant of */
  228.  
  229. {
  230.     if (islower(ch))
  231.         return(ch - DIFCASE);
  232.     else
  233.         return(ch);
  234. }
  235.  
  236. char PASCAL NEAR lowerc(ch)    /* return the lower case equivalant of a character */
  237.  
  238. char ch;    /* character to get lowercase equivalant of */
  239.  
  240. {
  241.     if (isupper(ch))
  242.         return(ch + DIFCASE);
  243.     else
  244.         return(ch);
  245. }
  246.  
  247. PASCAL NEAR initchars()    /* initialize the character upper/lower case tables */
  248.  
  249. {
  250.     /* there is nothing we need to do here! */
  251. }
  252.  
  253. /*    Set a character in the lowercase map */
  254.  
  255. int PASCAL NEAR setlower(ch, val)
  256.  
  257. char *ch;    /* ptr to character to set */
  258. char *val;    /* value to set it to */
  259.  
  260. {
  261.     return(*val & 255);
  262. }
  263.  
  264. /*    Set a character in the uppercase map */
  265.  
  266. int PASCAL NEAR setupper(ch, val)
  267.  
  268. char *ch;    /* ptr to character to set */
  269. char *val;    /* value to set it to */
  270.  
  271. {
  272.     return(*val & 255);
  273. }
  274. #endif
  275.